import Vue from 'vue';
import App from './App';
// import  './utils/interceptor.js'

import $mAssetsPath from '@/config/assets.config.js';
import $mConfig from '@/config/index.config.js';
import $mConstDataConfig from '@/config/constData.config.js';
import $mSettingConfig from '@/config/setting.config.js';
import $mRoutesConfig from '@/config/routes.config.js';

import store from '@/store';
import $mHelper from '@/utils/helper';
import $mRouter from '@/utils/router';


import Cache from '@/utils/cachetool'
Vue.prototype.$Cache = Cache;



Vue.prototype.$mAssetsPath = $mAssetsPath;
Vue.prototype.$mConfig = $mConfig;
Vue.prototype.$mConstDataConfig = $mConstDataConfig;
Vue.prototype.$mSettingConfig = $mSettingConfig;


Vue.prototype.$mStore = store;
Vue.prototype.$mHelper = $mHelper;
Vue.prototype.$mRouter = $mRouter;





import filters from './utils/filter.js';
import tabbar from './components/common/tabbar.vue';
import tabbarnew from './components/common/tabbarnew.vue';

import rfImage from '@/components/rf-image/rf-image';
import rfParser from '@/components/rf-parser';
// import rfEmpty from '@/components/rf-empty';
import rfLoading from '@/components/rf-loading';
// Vue.component('rfEmpty', rfEmpty);
// Vue.component('rfLoading', rfLoading);
// Vue.component('rfParser', rfParser);
// Vue.component('rfImage', rfImage);

import nodata from './components/common/nodata.vue';
import update from './components/common/update.vue';
import goodslist from './components/common/goodslist.vue';
import xcxheader from './components/common/xcxheader.vue';
import notice from './components/common/notice.vue';
import menu from './components/common/menu.vue';
import poster from './components/common/poster.vue';
Vue.config.productionTip = false
import i18n from './static/language/index.js'
Vue.prototype._i18n = i18n;
App.mpType = 'app'
import global from './utils/global.js';
import socket from './utils/socket.js';


import mapfun from './utils/mapfun.js';
Vue.prototype.mapfun = mapfun;


import uView from "uview-ui";
Vue.use(uView);

import { http } from './utils/request/index.js';
Vue.prototype.$http = http;

import request from "@/utils/request.js";
Vue.prototype.$request = request;

Vue.prototype.socket = socket;
Vue.prototype.Tips = global.Tips;
Vue.prototype.Modal = global.Modal;
Vue.prototype.copy = global.copy;
Vue.prototype.setCopy = global.setCopy;
Vue.prototype.go = global.go;
Vue.prototype.cGo = global.cGo;
Vue.prototype.makePhone = global.makePhone;
Vue.prototype.showMaoLocation = global.showMaoLocation;
Vue.prototype.back = global.back;
Vue.prototype.$toast = global.toast;
Vue.prototype.chatInit = global.chatInit;
Vue.prototype.openApp = global.openApp;
Vue.prototype.callPhone = global.callPhone;
Vue.prototype.addReverse = global.addReverse;
Vue.prototype.h5Reload = global.h5Reload;
Vue.prototype.clickBanner = global.clickBanner;
Vue.prototype.getUser = global.getUser;
Vue.prototype.previewImg = global.previewImg;
Vue.prototype.getBanner = global.getBanner;
Vue.prototype.goService = global.goService;
Vue.prototype.loginOut = global.loginOut;
Vue.prototype.changeLang = global.changeLang;
Vue.prototype.getStyle = global.getStyle;
Vue.component('tabBar',tabbar);
Vue.component('tabBarNew',tabbarnew);
Vue.component('noData',nodata);
Vue.component('upDate',update);
Vue.component('goodslist',goodslist);
Vue.component('xcxHeader',xcxheader);
Vue.component('menuBtn',menu);
Vue.component('poster',poster);
Vue.component('notice',notice);


import getlocation from '@/components/getlocation/index.vue';
Vue.component('getlocation', getlocation);

import ykAuthpup from "@/components/yk-authpup/yk-authpup";
Vue.component('ykAuthpup', ykAuthpup);




import headerBar from '@/components/header-bar.vue';
Vue.component('header-bar', headerBar);


import Loading from '@/components/loading/loadingnew.vue';
import rfLoadProgress from '@/components/rf-load-progress/rf-load-progress';
Vue.component('Loading', Loading);
Vue.component('rfLoadProgress', rfLoadProgress);




// 路由导航
$mRouter.beforeEach((navType, to) => {
	if (to.route === undefined) {
		throw '路由钩子函数中没有找到to对象，路由信息:' + JSON.stringify(to);
	}
	if (to.route === $mRoutesConfig.login.path && store.getters.isLogin) {
		uni.reLaunch({
			url: $mHelper.objParseUrlAndParam($mRoutesConfig.main.path)
		});
		return;
	}
	// 过滤需要权限的页面
	if (to.route.requiresAuth) {
		if (store.getters.isLogin) {
			// 已经登录
			uni[navType]({
				url: $mHelper.objParseUrlAndParam(to.route.path, to.query)
			});
		} else {
			// 登录成功后的重定向地址和参数
			const query = {
				redirectUrl: to.route.path,
				...to.query
			};
			// 没有登录 是否强制登录?
			if (store.state.forcedLogin) {
				uni.redirectTo({
					url: $mHelper.objParseUrlAndParam($mRoutesConfig.login.path, query)
				});
			} else {
				uni.navigateTo({
					url: $mHelper.objParseUrlAndParam($mRoutesConfig.login.path, query)
				});
			}
		}
	} else {
		uni[navType]({
			url: $mHelper.objParseUrlAndParam(to.route, to.query)
		});
	}
});

import $mPayment from '@/utils/payment';
Vue.prototype.$mPayment = $mPayment;

//过滤器统一处理加载
Object.keys(filters).forEach(key => {
	Vue.filter(key, filters[key])
})
const app = new Vue({
	...App,
	i18n,
	store,
	mocks: {
		$t: (a,b) => i18n.t(a,b), // 这里处理国际化
	},
})
app.$mount()
// const app = new Vue({
// 	...App,
// 	store,
// 	i18n,
// 	mocks: {
// 		$t: (a,b) => i18n.t(a,b), // 这里处理国际化
// 	},
// });
